<?php
class Controller_Declare extends FLEA_Controller_Action
{
	private $_ModelProduct;
	private $_ModelUserInfo;
	private $_ModelSearch;
	
	function actionIndex(){
		$rbac =& FLEA::getSingleton('FLEA_Rbac');	
		$user = $rbac->getUser();//获取登录用户信息

		$this ->_ModelUserInfo = & FLEA::getSingleton('Model_UserInfo');		
		$userInfo = $this ->_ModelUserInfo->analysisUserInfo($this ->_ModelUserInfo,$user['ID']);//获取用户更多其他详细信息
		
		//$this->_ModelProduct = & FLEA::getSingleton('Model_Product');
		$this->_ModelSearch = & FLEA::getSingleton('Model_Search');
		$sort = 'createtime desc';
		$limit = 20;
		$fields = 'id,name,createtime,pricetime,verifytime';
		$result = $this->_ModelSearch ->analysisResult($this->_ModelSearch,$sort,$limit,$fields);
		$viewData = array(
			'userInfo' => $userInfo,
			'list' => $result,
		);
		$this->_executeView('my_mycenter_list.html', $viewData);
	}
	
	function actionEdit(){
		$rbac =& FLEA::getSingleton('FLEA_Rbac');	
		$user = $rbac->getUser();//获取登录用户信息

		$this ->_ModelUserInfo = & FLEA::getSingleton('Model_UserInfo');		
		$userInfo = $this ->_ModelUserInfo->analysisUserInfo($this ->_ModelUserInfo,$user['ID']);//获取用户更多其他详细信息
		
		is_numeric($_GET['id'])?$id = $_GET['id']:redirect(url('Declare'));
		$this ->_ModelProduct = & FLEA::getSingleton('Model_Product');
		$result = $this ->_ModelProduct -> find($id);
		
//		dump($result);exit;
		
		$viewData = array(
			'userInfo' => $userInfo,
			'list' => $result,
		);
		$this->_executeView('my_mycenter_list_detail.html', $viewData);
	}
	
	function actionAdd(){
		$rbac =& FLEA::getSingleton('FLEA_Rbac');	
		$user = $rbac->getUser();//获取登录用户信息

		$this ->_ModelUserInfo = & FLEA::getSingleton('Model_UserInfo');		
		$userInfo = $this ->_ModelUserInfo->analysisUserInfo($this ->_ModelUserInfo,$user['ID']);//获取用户更多其他详细信息
		
		$viewData = array(
			'userInfo' => $userInfo,
			'do'=>'add',
		);
		$this->_executeView('my_mycenter_list_detail.html', $viewData);
	}
	
	function actionChange(){
//		dump($_POST);
		$this ->_ModelProduct = & FLEA::getSingleton('Model_Product');
		foreach ($_POST as $key => $value){
			$$key = addslashes(trim($value));
		}
		
		$list = array(
			'id' => $id,
			'name' => $name,
			'range' => $range,
			'part' => $part,
			'norm' => $norm,
			'pack'=> $pack,
			'sterilizing'=> $sterilizing,
			'position'=>$position,
			'directoryName'=>$directoryName,
			'clinicalName'=>$clinicalName,
			'productNumber'=>$productNumber,
			'format'=>$format,
			'model'=>$model,
			'material'=>$material,
			'brand'=>$brand,
			'location'=>$location,
			'isForeign'=>$origin,
			'findId'=>$find,
			'cert' => array(
				'id'=>$cert_id,
				'oldNumber'=>$oldNumber,
				'oldValidDate'=>$oldValidDate,
				'noteNumber'=>$noteNumber,
				'noteValidDate'=>$noteValidDate,
				'newNumber'=>$newNumber,
				'newValidDate'=>$newValidDate,
				'FDAnumber'=>$FDAnumber,
				'FDAvalidDate'=>$FDAvalidDate,
				'ECnumber'=>$ECnumber,
				'ECvalidDate'=>$ECvalidDate,
				'CMDproductNumber'=>$CMDproductNumber,
				'CMDprodactDate'=>$CMDprodactDate,
				'CMDqualityNumber'=>$CMDqualityNumber,
				'CMDqualityDate'=>$CMDqualityDate,
				'CMDproductISOnumber'=>$CMDproductISOnumber,
				'CMDproductISOdate'=>$CMDproductISOdate,
			),
			'p_company' => array(
				'id'=>$p_company_id,
				'name'=>$p_company_name,
				'permitNumber'=>$p_company_permitNumber,
				'permitValidDate'=>$p_company_permitValidDate,
				'licenceNumber'=>$p_company_licenceNumber,
				'licenceValidDate'=>$p_company_licenceValidDate,
				'produceNumber'=>$p_company_produceNumber,
				'produceValidDate'=>$p_company_produceValidDate,
			),
			'd_company' => array(
				'0' => array(
					'declare_id'=>$d_company_id,
					'name'=>$d_company_name,
					'permitNumber'=>$d_company_permitNumber,
					'permitValideDate'=>$d_company_permitValidDate,
					'telephone'=>$d_company_telephone,
					'contactPerson'=>$d_company_contactPerson,
					'contactPersonCellphone'=>$d_company_contactPersonCellphone,
					'contactPersonTelephone'=>$d_company_contactPersonTelephone,
					'legalPersonId'=>$legalPersonId,
				),
			),
			
		);
		
		if($do == 'add'){
			$list['createtime'] = date('Y-m-d');
		}
		
		$this ->_ModelProduct->save($list);
		redirect(url('Declare'));		
		
	}
} 
?>